import {
	apiUrl
} from "./donman.js"

function sendAjax(method = "GET", path = "/", data = {}) {
	const userinfo = uni.getStorageSync("userinfo");
	let token = "";
	if (typeof userinfo === "object" && userinfo.token) {
		token = userinfo.token;
		// console.log(token);
	}
	return new Promise((resolve, reject) => {
		uni.request({
			method,
			url: apiUrl + path,
			data,
			header: {
				token,
			},
			success: (res) => {
				resolve(res)
			},
			fail: (e) => {
				reject(e)
			}
		})
	})
}

export default sendAjax;
